package com.sky.annotations;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

import java.io.IOException;

public class SexDeserializer extends StdDeserializer<String> {

	public SexDeserializer() {
		this(null);
	}

	public SexDeserializer(Class<?> vc) {
		super(vc);
	}

	@Override
	public String deserialize(JsonParser jp, DeserializationContext ctxt)
			throws IOException {
		JsonNode node = jp.getCodec().readTree(jp);
		int sexCode = node.asInt();
		if (sexCode == 1) {
			return "男";
		} else if (sexCode == 0) {
			return "女";
		} else {
			return "未知";
		}
	}
}
